package Selenium.CommonFunctions;

import java.util.ArrayList;
import java.util.List;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;


//This is a library that contains advance webelemnt find functions

//All the members in the class should start with public static
public class AdvanceFindElementFunctions {	
	///Find member based on attributes not part of a selenium's By class
	//Returns the first element found in the parent element
	public static WebElement FindElement(WebElement ParentWebElement,String TagName, String Attribute, String value)
	{
		WebElement TargetElement = null;
		List<WebElement> ElementList = new ArrayList<WebElement>();		
		ElementList = ParentWebElement.findElements(By.tagName(TagName));
		
		if(ElementList.size() >=0)
		{
			System.out.println("Number of elements found with tag name: " + TagName + " is: " + ElementList.size());
			for(int i = 0;i <= ElementList.size() - 1; i++)
			{
				System.out.println(ElementList.get(i).getAttribute(Attribute).trim() + ".");
				System.out.println(value + ".");
				if(ElementList.get(i).getAttribute(Attribute).trim().equals(value))
				{
					TargetElement = ElementList.get(i);
					break;
				}
			}
		}		
		return TargetElement;		
	}
}
